import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

public class Solution981 {

    Map<String, TreeMap<Integer,String>> map;

    public Solution981() {
        map=new HashMap<>();
    }

    public void set(String key, String value, int timestamp) {
        TreeMap<Integer,String> treeMap=map.getOrDefault(key,new TreeMap<>());
        treeMap.put(timestamp,value);
        map.put(key,treeMap);
    }

    public String get(String key, int timestamp) {
        TreeMap<Integer,String> treeMap=map.getOrDefault(key,new TreeMap<>());
        if (treeMap.isEmpty()){
            return "";
        }else{
            Integer i=treeMap.floorKey(timestamp);
            return i==null?"":treeMap.get(i);
        }
    }

    public static void main(String[] args) {
        Solution981 solution981=new Solution981();
        solution981.set("foo","bar",1);
        System.out.println(solution981.get("foo",1));
        System.out.println(solution981.get("foo",3));
        solution981.set("foo","bar2",4);
        System.out.println(solution981.get("foo",4));
        System.out.println(solution981.get("foo",5));
        System.out.println(solution981.get("foo",-1));
    }
}
